using System;
using System.Collections.Generic;
using System.Text;

namespace Geekees.App.Cashbook.Lib.Helper
{
	public class TimeZoneHelper
	{
		public static WindowsTimeZone GetTimeZone( int timeZoneId )
		{
			foreach( WindowsTimeZone wtz in WindowsTimeZone.TimeZones )
			{
				if( wtz.Id == timeZoneId )
					return wtz;
			}

			return null;
		}
		public static int GetTimeZoneOffset( int serverTimeZone, int currentTimeZoneId, DateTime time )
		{
			// determine the time offset based on the data's timezone Id hash.
			foreach( WindowsTimeZone wtz in WindowsTimeZone.TimeZones )
			{
				if( wtz.Id == currentTimeZoneId )
				{
					return ( serverTimeZone -
							  ( wtz.IsDaylightSavingTime( time ) ? wtz.DaylightBias.Hours : wtz.BaseBias.Hours ) );
				}
			}

			// if we made it this far, we couldn't find the currentTimeZoneId. This can happen if the datastore
			// has an actual timeZone offset, rather than a TimeZoneId. Just return the serverTZ - currentTimeZoneId.
			return serverTimeZone - currentTimeZoneId;
		}
	}
}
